<template>
    <div>
        <h1>正在跳转中。。。。</h1>

        <h2>获取的微博code是：{{weibo_code}}</h2>
    </div>
</template>

<script>
import axios from 'axios'
export default {
    name:"weibo_callhack",
    data(){
        return{
            weibo_code:""
        }
    },
    methods:{
        get_weibo_code(){
            var code = this.$route.query.code
            console.log(code);
            this.weibo_code =code
        },
        send_weibo(){
           axios({
               url:"http://127.0.0.1:8000/mds/weibocode/",
               method:"GET",
               params:{"code":this.weibo_code}
           }).then(res=>{
               console.log(res.data);
               if(res.data.code==200){
                   sessionStorage.setItem("jwt_token",res.data.token)
                   window.localStorage.href = 'https://www.baidu.com'
               }else if(res.data.code==404){
                   //第一次登录，需要绑定信息
                   sessionStorage.setItem("uid",res.data.uid)
                   this.$router.push({path:"/semuser"})
               }else{
                   alert("微博登录失败，请重试")
               }
           })
        }
    },
    mounted(){
        this.get_weibo_code(),
        this.send_weibo()
    }
}
</script>

<style>

</style>
